<?php
include 'common/autoload.php';
include 'common/Prod_Common.php';
include 'common/prodField.php';

use pft\Prod\Product;
$titleText = '新增门票';
$navText = '新增门票';
$gourl = $background ? 2 : 1;
$isedit = false;
$iscopy = $_GET['act'] && $_GET['act']=='copy' ? 1:0;
$obj = new Product($GLOBALS['le']);
$sid = abs($_GET['sid']);//景区ID
$jiutian_bindFlag = false;// 是否需要绑定九天闸机
$ticket_id = abs($_GET['prod_id']);//产品ID
if(!$sid && !$ticket_id) exit('<script>alert("访问参数出错");history.go(-1);</script>');
if($iscopy) $otherParams = '&act=copy&c_title=' .urlencode($_GET['c_title']);

$apply_did = $_SESSION['dtype']==6? $_SESSION['sid'] : $_SESSION['memberID'];

if($_SESSION['dtype']!=9){
    if($_SESSION['dtype']==6) {
        if(\pft\Member\MemberAccount::GetMemType($_SESSION['sid'])!=0) {
            exit('您的上级不是供应商身份，无法发布产品。');
        }
    }
    elseif($_SESSION['dtype']!=0) {
        exit('您不是供应商身份，无法发布产品。');
    }

    $sel_apply_did = "select apply_did from uu_land where id=$sid limit 1";
    $le->query($sel_apply_did);
    $row = $le->fetch_assoc();
    if($row['apply_did']!=$apply_did)
        exit('<script>alert("这不是你的产品")</script>');
}
if($ticket_id) {
    $isedit = true;
    $ticket_id = abs($_GET['prod_id']);//门票id

    $data = ($_SESSION['dtype']==9) ?
    $obj->GetTicketById($ticket_id):$obj->GetTicketById($ticket_id, $apply_did);
    
    $apply_did = $data['apply_did'];
    $data_f = $obj->GetProdcutExt($ticket_id );//扩展表里面的数据

    $ass = '';//集合地点
    if($data_f['ass_station']) $ass = implode(';',unserialize($data_f['ass_station']));
    $tid = $data['id'];
    $pid = $data['pid'];
    $pobj = new Price($pid);
    $titleText = $data['title'];
    $navText = '门票编辑';
    $startplace = $data_f['startplace'];
    $endplace = $data_f['endplace'];
}
$scenryData = $obj->GetSceneryTitle($sid);
$ptype = $scenryData['p_type'];
$notify_num = $scenryData['fax'];
if($ptype=='B' && !$ticket_id) {
    $startplace = substr($scenryData['runtime'],0,strpos($scenryData['runtime'],'|'));
    $endplace = substr($scenryData['runtime'],strpos($scenryData['runtime'],'|')+1);
}

$titleText = $scenryData['title'].'--'.$titleText;

if ($data['sync_id'] && $data['sync_status']==2) {
    $btnWrap = '同步的产品禁止修改操作';
}
else {
    $btnWrap = '<button class="ui-button ui-button-lblue" id="saveTicket" type="button">保存</button>';
}

//查询是否有给绑定闸机的权限
$str_ticket = "SELECT jiutian_auth FROM pft_member_extinfo WHERE fid=".$_SESSION['sid'] ." limit 1";
$GLOBALS['le']->query($str_ticket);
$GLOBALS['le']->fetch_assoc();
$jiutian_auth =  $GLOBALS['le']->f('jiutian_auth');

// 需要绑定闸机的产品ID（tid）
$needBind = array(
	'1976',	'4314',	'4313',	'5604',	'5603',	'5523',	'5522',	'5521',	'5520',	'3950',	'3949',	'3911','5857','5818','5817','5816','6047','6049','5959','5958','5957','6060','6059','6062','6061','6044','6042','4313','4314','5567','7177','9746','6042','6044','9833','9832','9962','10003','9962','9963','9964','9965','9904','9948','9949','9901',
'9873','9874','9862','9863','9836','9837','9855','9856','9830','9831','9829','9826','9809','9810','9811','9812','10004','10392','10405'
);
if($jiutian_auth == 1 || in_array($_REQUEST['prod_id'],$needBind) || $_SESSION['sid']==7132){ 
	// 绑定闸机票类数据（自己生成，九天不提供）
	$tmp = array();
	$md5 = md5($scenryData['title'].'-'.$_REQUEST['prod_id']);
	$jiuTians[] = array('uuid'=>$md5,'name'=>$data['title']);
    $jiutian_bindFlag = true;
}

if($_SESSION['sid'] == 7517 ){
	// 鼓浪屿绑定闸机票类数据
	$jiuTians = file_get_contents('http://117.29.178.154:8000/et/ebusiness/ticketInfo.do');
	$jiuTians = json_decode($jiuTians,true);
    $jiuTians = $jiuTians['content'];
    $jiutian_bindFlag = true;
}


$page_title = "票类编辑 - ";
include 'common/header.html';
include 'common/left.html';
include TPLPATH.'ticket_edit_y.tpl';
include('common/footer.html');